package org.byqh.dqeai.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.byqh.dqeai.common.Json;
import org.byqh.dqeai.dto.SysAccessLogDTO;
import org.byqh.dqeai.dto.common.IPage;
import org.byqh.dqeai.entity.SysAccessLog;
import org.byqh.dqeai.entity.proxy.SysAccessLogProxy;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysAccessLog")
@Tag(name = "系统[SysAccessLog] - 访问日志管理")
public class SysAccessLogController extends BaseController<SysAccessLog, SysAccessLogProxy> {
    /**
     * 分页查询数据
     */
    @PostMapping(value = "/list")
    public Json<IPage<SysAccessLog>> list(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          @RequestParam(defaultValue = "", required = false) String sort,
                                          @RequestBody(required = false) SysAccessLogDTO dto) {

        return this.listPageImpl(SysAccessLog.class, page, size, (query) -> {
            if (dto != null) {
                if (!StringUtils.isBlank(dto.getAppId())) {
                    query = query.where(r -> r.appId().eq(dto.getAppId()));
                }
            }

            return query;
        });
    }
}